import Vue from 'vue'
import VueRouter from 'vue-router'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

// let modules = []
// const modulesFiles = require.context('./modules', false, /\.js$/)

// modulesFiles.keys().map(item => {
//   modules = [...modules, ...modulesFiles(item).default]
// })

Vue.use(VueRouter)

const routes = [
  {
		path: '*',
		name: '首页',
		component: () => import("@/views/Index"),
		meta: {
			title: '首页'
		}
  },
	{
		path: '/Login',
		name: '登录',
		component: () => import("@/components/vessel/Login"),
		meta: {
			title: '登录'
		}
	},
	{
		path: '/Myteam',
		name: '我的团队',
		component: () => import("@/components/vessel/page/Myteam"),
		meta: {
			title: '我的团队'
		}
	},
	{
		path: '/BankCard',
		name: '我的银行卡',
		component: () => import("@/components/vessel/page/BankCard"),
		meta: {
			title: '我的银行卡'
		}
	},
	{
		path: '/MyAssets',
		name: '我的资产',
		component: () => import("@/components/vessel/page/MyAssets"),
		meta: {
			title: '我的资产'
		}
	},
	{
		path: '/PromotionPage',
		name: '我的推广',
		component: () => import("@/components/vessel/page/PromotionPage"),
		meta: {
			title: '我的推广'
		}
	},
	{
		path: '/Feedback',
		name: '投诉反馈',
		component: () => import("@/components/vessel/page/Feedback"),
		meta: {
			title: '投诉反馈'
		}
	},
	{
		path: '/MyCustomer',
		name: '我的客服',
		component: () => import("@/components/vessel/page/MyCustomer"),
		meta: {
			title: '我的客服'
		}
	},
	{
		path: '/Withdrawal',
		name: '提现',
		component: () => import("@/components/vessel/page/Withdrawal"),
		meta: {
			title: '提现'
		}
	},
	{
		path: '/WithdrawalRecord',
		name: '提现记录',
		component: () => import("@/components/vessel/page/WithdrawalRecord"),
		meta: {
			title: '提现记录'
		}
	},
	{
		path: '/InfoReder',
		name: '确认订单',
		component: () => import("@/components/vessel/page/InfoReder"),
		meta: {
			title: '确认订单'
		}
	},
  {
    path: '/404',
		name: '404',
    component: () =>
      import('@/components/404.vue'),
			meta: {
				title: '404'
			}
  },
]

const router = new VueRouter({
  mode: 'history', // 默认时hash 但是路径会有# 
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {//beforeEach是router的钩子函数，在进入路由前执行
  if (to.meta.title) {//判断是否有标题
    document.title = to.meta.title
  }
	if (to.path !== from.path) {
	  NProgress.start() //进度条加载
	}
  next()
})


router.afterEach(() => {
  NProgress.done() //进度条结束
})

export default router
